package com.demo.service.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo.mapper.CanvasMapper;
import com.demo.model.Canvas;
import com.demo.service.CanvasService;
import com.demo.utils.UUIDUtis;

@Service
public class CanvasServiceImpl implements CanvasService{
	
	@Autowired
	private CanvasMapper canvasMapper;
	
	@Override
	public List<Canvas> findByOwner(String userId) {
		return canvasMapper.findByOwner(userId);
	}

	@Override
	public Canvas get(String id) {
		return canvasMapper.selectByPrimaryKey(id);
	}

	@Override
	public Canvas saveLayout(Canvas canvas) {
		//获取当前个人的排序
		int maxSort = canvasMapper.getMaxSort("1");
		canvas.setSort(maxSort + 1);
		canvas.setOwner("1");
		canvas.setId(UUIDUtis.get());
		canvasMapper.insert(canvas);
		return canvas;
	}

}
